import { defineStore } from 'pinia'
import { ElMessage } from 'element-plus'
interface Dish {
  id: number;
  name: string;
  price: number;
  image: string;
  description: string;
}

export const useCartStore = defineStore('cart', {
  state: () => ({
    items: [] as Array<{ dish: Dish; quantity: number }>
  }),
  getters: {
    totalPrice: (state) => 
      state.items.reduce((total, item) => total + item.dish.price * item.quantity, 0)
  },
  actions: {
    addItem(dish: Dish) {
      const existing = this.items.find(item => item.dish.id === dish.id)
      existing ? existing.quantity++ : this.items.push({ dish, quantity: 1 })
    },
    removeItem(id: number) {
      this.items = this.items.filter(item => item.dish.id !== id)
    }
  }
})